const {get,post} = require("../utils/requert");

export function getuserInof(){
  return get("/api/login-user/info").then(res=>{
    const app=getApp()
    if(res.data.code==0){
      app.globalData.islogin=true
      app.globalData.username=res.data.data
    }else{
      app.globalData.islogin=false
      app.globalData.username=null
    }
    return res
  })
}
export function login(username,password){
  return post("/api/login", {
    username: username,
    password: password,
    rememberMe: false,
  }).then(res => {
    console.log(res);
    if (res.data.code == 0) {
      res.cookies.forEach((item) => {
        if (item.includes("JSESSIONID")) {
          wx.setStorageSync('jsonid', item)
        }
      })
      const app=getApp()
      app.globalData.islogin=true
      app.globalData.username=res.data.data
   
      // get("/api/login-user/info").then(res=>{
      //   console.log(res);
      // })
    }
    return res
  });
  
}
// 新闻列表
export function banner(pageNum=1,pageSize=10,){
  const parmas={
    pageNum,
    pageSize
  }
  return post("/api/cms/article/open/list",parmas).then(res=>{
    console.log(res);
    return res
  })
  
}
// 轮播图
export function listbanner(pageNum=1,pageSize=4){
  const list={
    pageNum,
    pageSize
  }
  return post("/api/cms/article/open/banner/list",list).then(res=>{
    return res
  })
}

export function getPosts(pageNum=1,pageSize=30){
  return post('/api/bbs/bbsPosts/open/list',{
    pageNum,
    pageSize
  })
}